﻿using System;

namespace LabColorPicker {

    public static class MathX {

        public static double Clamp( double value, double maximum ) {
            return Math.Min( Math.Max( value, 0d ), maximum );
        }

        public static double Scale( double value, double oldRange, double newRange ) {
            return value / oldRange * newRange;
        }

        public static double ClampedScale( double value, double oldRange, double newRange ) {
            return Scale( Clamp( value, oldRange ), oldRange, newRange );
        }

        public static double Translate( double value, double distance ) {
            return value + distance;
        }

    }

}
